package io.github.bloquesoft.entity.storage.analysis;

import io.github.bloquesoft.entity.storage.PojoOperation;
import io.github.bloquesoft.entity.value.EntityValue;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class StorageEntityAnalysisResult {

    public void storage(EntityAnalysisResult result, PojoOperation operation)
    {
        log.info("Storage entity start, target entity id : " + result.getTargetRoot().getId());
        for(EntityValue entityValue : result.getInsertList())
        {
            entityValue.handleParentIdPojoProperty();
            operation.create(entityValue.getEntityDefinition(), entityValue.getValue());
        }

        for(EntityValue entityValue : result.getUpdateList())
        {
            operation.update(entityValue.getEntityDefinition(), entityValue.getValue());
        }

        for(EntityValue entityValue : result.getDeleteList())
        {
            operation.delete(entityValue.getEntityDefinition(), entityValue.getValue());
        }
        log.info("Storage entity end, target entity id : " + result.getTargetRoot().getId());
    }
}